#include "mystdio.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>


myFILE *myfopen(const char *pathname, const char *mode)
{
    int fd = -1;
    int flags = 0;
    if(strcmp(mode, "r") == 0)
    {
        flags =  O_RDONLY;
        fd = open(pathname,flags);
    }
    else if(strcmp(mode, "w") == 0)
    {
        flags = O_WRONLY | O_CREAT | O_TRUNC;
        fd = open(pathname, flags);
    }
    else if(strcmp(mode, "a") == 0)
    {
        flags = O_WRONLY | O_CREAT | O_APPEND;
        fd = open(pathname, flags);
    }
    else
    {
        //TODO
    }
    if(fd < 0) return NULL;

    myFILE *fp = (myFILE*)malloc(sizeof(myFILE));

    if(fp == NULL) return NULL;
    
    fp->fd = fd;
    fp->flags = flags; 

}
int myfputs(const char *str, myFILE *fp)
{
    return 0;
}
void myfflush(myFILE*fp)
{}
void myfclose(myFILE *fp)
{}

